package cate.game.pvp.throne.data.ko;

import cate.common.table.d.GDThrone;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;


@NoteClass("王座争霸-淘汰赛-分组赛")
public class TBKoDivide {

	@NoteField("匹配信息")
	public List<TBKoMatch> matchs;

	public void initialize() {
		if (matchs == null) {
			matchs = new ArrayList<>();
		}
	}

	public TBKoMatch findMatch(int matchGroup) {
		for (TBKoMatch match : matchs) {
			if (match.matchGroup == matchGroup) {
				return match;
			}
		}
		return null;
	}

	public List<TBKoReport> findRoleReports(String roleUid) {
		List<TBKoReport> result = new ArrayList<>();
		for (TBKoMatch match : matchs) {
			if (match.containRole(roleUid)) {
				result.add(TBKoReport.of(GDThrone.KO_DIVIDE_ROUND, match));
				break;
			}
		}
		return result;
	}

	@JsonIgnore
	public TBKoMatch getOrBuildMatch(int matchGroup) {
		TBKoMatch match = findMatch(matchGroup);
		if (match == null) {
			match = new TBKoMatch(matchGroup);
			match.initialize();
			this.matchs.add(match);
		}
		return match;
	}

	public void clear() {
		matchs.clear();
	}
}
